package logic

import (
	"context"
	"house_srv/model/mysql"

	"house_srv/internal/svc"
	"house_srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 列表
func (l *HouseListLogic) HouseList(in *srv.HouseListRequest) (*srv.HouseListResponse, error) {
	// todo: add your logic here and delete this line

	var house []mysql.House
	mysql.DB.Debug().Find(&house)
	var lists []*srv.HouseList
	for _, m := range house {
		list := srv.HouseList{
			Name:    m.Name,
			Address: m.Address,
			Area:    m.Area,
			Price:   float32(m.Price),
			Image:   m.Image,
			Id:      int64(m.ID),
		}
		lists = append(lists, &list)
	}
	return &srv.HouseListResponse{
		List: lists,
	}, nil
}
